﻿ using System;
    using System.Web;
    using System.Web.Routing;

namespace Wild2.Models.Constraints
{
    public class NotEqual : IRouteConstraint
    {
        private readonly string _match = String.Empty;

        public NotEqual(string match)
        {
            _match = match;
        }

        public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
        {
            string[] match = _match.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
            bool allow = true;
            foreach (string item in match)
            {
                if (String.Compare(values[parameterName].ToString(), item, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    allow = false;
                    break;
                }
            }
            return allow;
        }
    }
}